﻿@model b7.ViewModels.ShoppingCartViewModel

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Shopping.cshtml";
}
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js" )" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        // Document.ready -> link up remove event handler
        $(".RemoveLink").click(function () {
            // Get the id from the link
            var recordToDelete = $(this).attr("id");
            if (recordToDelete != '') {
                // Perform the ajax post
                $.post("/ShoppingCart/RemoveFromCart", { "id": recordToDelete },
                    function (data) {
                        // Successful requests get here
                        // Update the page elements
                        if (data.ItemCount == 0) {
                            $('#row-' + data.DeleteId).fadeOut('slow');
                        } else {
                            $('#item-count-' + data.DeleteId).text(data.ItemCount);
                        }
                        $('#cart-total').text(data.CartTotal);
                        $('#update-message').text(data.Message);
                        $('#cart-status').text('Cart (' + data.CartCount + ')');
                    });
            }
        });
    });
</script>


@*<div id="update-message">
</div>*@
@*@foreach(var item1 in Model.CartItems.)*@
<div class="mota">
<div class="tieude">Giỏ hàng</div>
<table border="1">
    <tr>
        <th>
            Images
        </th>
        <th>
            Album Name
        </th>
        <th>
            Price (each)
        </th>
        <th>
            Quantity
        </th>
        <th>Action</th>
    </tr>
    @foreach (var item in Model.CartItems)
    {        
        <tr id="row-@item.RecordId">
            @Html.HiddenFor(modelItem=>item.SanphamId)
            <td>
                <img src="../..@Html.DisplayFor(modelItem => item.Sanpham.Anh)" height="50px" width="50px">
            </td>
            <td>
                @Html.ActionLink(item.Sanpham.Name,"chitietsp", "Home", new { id = item.SanphamId }, null)
            </td>
            <td>
                @item.Sanpham.SalePrice
            </td>
            <td id="item-count-@item.RecordId">
                @*@item.Count*@
                @Html.EditorFor(model=>model.CartItems.Count)
            </td>
            <td>
               <a href="#" class="RemoveLink" id="@item.RecordId">Remove from cart</a>
            </td>
        </tr>
    }
    <tr>
        <td>
            Total
        </td>
        <td>
        </td>
        
        <td id="cart-total" colspan="3">
            @Model.CartTotal
        </td>
    </tr>
    <tr>
        <td colspan="2">@Html.ActionLink("Addmore","Index","Home")</td>
        <td >@Html.ActionLink("Buy", "UpdateQuantity", "ShoppingCart")</td>
        <td>@Html.ActionLink("Checkout", "AddressAndPayment", "Checkout")</td>
    </tr>
</table>
</div>
